<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ include file="/taglibs.jsp"%>

<%@page import="java.util.Date"%><s:url value="/js" var="jsPath"/>
<s:url value="/css" var="cssPath"/>
<s:url value="/images" var="imgPath"/>

<head>
	<style type="text/css">
	h1 span{visibility:visible;}
	td span{visibility:visible;}
	.msg{float:left; line-height:1em; margin:0; display:block;border:1px solid #f66;padding:2px 5px;*padding:2px 5px 1px;}
	.msg.rn{background-color:#fff2f2;border-color:#f66;}
	</style>
</head>

<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath() %>'/>
<c-rt:set var="frontHostname" value='<%=ServerValue.getFrontHostname() %>'/>
<%-- 月历 --%>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/yaodian100.common.js"></script>

<script>
$().ready(function () {
	$('#paramStartDate').datepick({minDate: null, showOn: 'both',
		buttonImageOnly: true, buttonImage: '${imgPath}/calendar.gif',numberOfMonths:2,dateFormat:"yy-mm-dd",yearRange: '-50:+50'});
	$('#paramEndDate').datepick({minDate: new Date(), showOn: 'both',
		buttonImageOnly: true, buttonImage: '${imgPath}/calendar.gif',numberOfMonths:2,beforeShow:customRange,dateFormat:"yy-mm-dd",yearRange: '-50:+50'});
});

function customRange (){
	var startDt = $('#paramStartDate').val(); //起始日
	var endDt = new Date(parseInt(startDt.substring(0,4),10),parseInt(startDt.substring(5,7),10)-1,parseInt(startDt.substring(8,10),10)); //結束日
	return {minDate:endDt}; 
}
</script>

<s:if test="hasErrors()">
<p><s:actionerror cssClass="msg rn" /></p>
</s:if>
<s:if test="hasActionMessages()">
<p><s:actionmessage cssClass="msg rn" /></p>
</s:if>
<s:if test="hasFieldErrors()">
<p><s:fielderror cssClass="msg rn" /></p>
</s:if>

<h1>信用卡活动管理<br>
<div class="f-link"><a href="add.do">新增</a> <a href="#" onclick="document.campaignForm.submit();">搜寻</a></div>
</h1> 

<s:form action="campaign/search.do" namespace="/creditcard" method="post" name="campaignForm">
<table width="100%">
	<tr>
		<td width="15%">活动名称：</td>
		<td colspan="3">
			<s:textfield name="paramName" />
		</td>
	</tr>
	<tr>
		<td width="15%">活动时间：</td>
		<td width="35%">
			<input name="paramStartDate" id="paramStartDate" size="10" value="${paramStartDate}">
			~
			<input name="paramEndDate" id="paramEndDate" size="10" value="${paramEndDate}">
		</td>
		<td width="15%">Domain：</td>
		<td width="35%">
			<s:select name="paramDomain" list="menuDomain.options" headerKey="" headerValue="全部" listKey="key" listValue="value.name"/>
		</td>
	</tr>
	<tr>
		<td width="15%">启用：</td>
		<td width="35%">
			<s:checkboxlist list="#{'true':'是','false':'否'}" listKey="key" listValue="value" name="paramEnable"/>
		</td>
		<td width="15%">活动范围：</td>
		<td width="35%">
			<s:checkboxlist list="menuRange" name="paramRanges" listValue="desc" />
		</td>
	</tr>
</table>
</s:form>
<br/>

<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tb-1">
	<thead>
		<tr>
			<th>#</th>
			<th>行销活动名称</th>
			<th>範圍</th>
			<th>活动时间</th>
			<th>Domain</th>
			<th>启用</th>
			<th>&nbsp;</th>
		</tr>
	</thead>
	<s:if test="%{campaignList.size > 0}">
	<tbody>
		<s:iterator value="campaignList" var="campaign" status="idx">
			<s:set name="i" value="%{#idx.index}" />
			<s:set name="no" value="%{#i + 1}" />
		<tr class="${no%2==0 ? 'bg-yl' : ''}">
			<td><fmt:formatNumber pattern="0000" value="${no + pager.currentPage*20}" /></td>
			<td style="text-align: left"><a href="edit.do?creditcardId=${campaign.id}" >${campaign.campaignName}</a></td>
			<td>
				<c:out value="${campaign.range.desc}"/>
				<c:if test="${campaign.range.code eq 'Category'}">
				<br/>${campaign.campaignRangeDet}
				</c:if>
			</td>
			<c:set var="fontColor" value="block"/>
			<c:if test="${campaign.startDate ge now}"><c:set var="fontColor" value="green"/></c:if>
			<c:if test="${campaign.endDate le now}"><c:set var="fontColor" value="green"/></c:if>
			<td style="color:${fontColor}" >
				<fmt:formatDate value="${campaign.startDate}" pattern="yyyy-MM-dd HH:mm" />~<fmt:formatDate value="${campaign.endDate}" pattern="yyyy-MM-dd HH:mm" />
			</td>
			<td>${menuDomain.options[campaign.domain].name}</td>
			<td><c:if test="${campaign.enable}">是</c:if><c:if test="${!campaign.enable}"><div style="color:green">否</div></c:if></td>
			<td><a href="delete.do?creditcardId=${campaign.id}">删除</a></td>
		</tr>
		</s:iterator>
	</tbody>
	</s:if>
	<s:else>
	<tbody>
		<tr class="bg-yl"><td colspan="6">查无资料!!</td></tr>
	</tbody>
	</s:else>
</table>
<yaodian100:pageutil link="search.do" pagerObj="${pager}" />